package org.example;
import edu.whu.*;

// 使用InitMethod注解

import edu.whu.Myclass;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        System.out.println("Hello world!");
        Properties properties = new Properties();
        try {
            properties.load(ClassLoader.getSystemResourceAsStream("myapp.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        String ClassName = properties.getProperty("bootstrapClass");
        Class<?> clazz = Class.forName(ClassName);
        Object obj = clazz.getDeclaredConstructor().newInstance();
        for(Method m : clazz.getMethods()) {
            if(m.isAnnotationPresent(com.example.InitMethod.class)) {
                m.invoke(obj);
            }
        }
        String ClassName1 = properties.getProperty("bootstrapClass1");
        Class<?> clazz1 = Class.forName(ClassName1);
        Object obj1 = clazz1.getDeclaredConstructor().newInstance();
        for(Method m : clazz1.getMethods()) {
            if(m.isAnnotationPresent(com.example.InitMethod.class)) {
                m.invoke(obj1);
            }
        }

    }
}